<template>
  <div class="hospital">
    <doctor-options @search="search" ref="doctorOptions"/>
    <doctor-table @search="search" :loading="loading" :data="data"/>
    <div class="demonstration-box">
        <!-- <span class="demonstration">显示总数</span> -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageParams.size"
          layout="total, prev, pager, next"
          :total="pageParams.totalCount"
        ></el-pagination>
      </div>
  </div>
</template>

<script>
import DoctorOptions from './controls/doctorOptions'
import DoctorTable from './controls/doctorTable'
import { doctorTitleList } from "data/listBody"
import queryString from "querystring"
import page from 'data/page'

export default {
  name: 'doctor',
  mixins: [page],
  data() {
    return {
      data:[], //table数据
      currentPage: 1,
      loading: false
    }
  },
  components: {
    DoctorOptions,
    DoctorTable
  },
  mounted(){
    this.search();
  },
  methods:{
    search(){  //搜索
      this.loading = true;
      const optionParams = this.$refs.doctorOptions.getData();
      const tableParams = {
        size: 20,
        page: this.currentPage -1
      };
      let params = this.lodash.assign({}, optionParams, tableParams);
      const param = queryString.stringify(params || {});
      this.api.get(`/doctor?${param}`).then((res)=>{
        this.loading = false;
        if(!res.data) return;
        this.data = res.data.list;
        this.setPage(res.data)
        this.dataInit();
      }).catch((err) => {
        console.log(err)
        this.loading = false;
        this.$message(err.data)
      })
    },
    dataInit(){ //数据初始化
      this.data.map((item) => {
        if( item.country ) item.address = item.address || `${item.provinceValue}-${item.cityValue}-${item.countryValue}`;
        let docArr = doctorTitleList.filter(obj => {
          return obj.id == item.level;
        })
        if(docArr.length > 0) return item.levelName = docArr[0].dValue;       
        return item;
      })
    }
  },
  watch: {
    currentPage() {
      this.search()
    }
  }
}
</script>
 
<style lang="less" scoped>

</style>
 